﻿$(function () {
    getList(0);
    getRobotRunningStatus();
    //setInterval("getRobotRunningStatus();", 5000);
    //            $("#txtSearch").autocomplete("jsonHandler.ashx?t=name");
});
function buildItemsPager(c, t) {
    $("#divItemsPgr").pagination(t, { num_edge_entries: 2, current_page: c,
        num_display_entries: 20, load_first_page: false,
        callback: function (p, q) { getList(p); return false; }, items_per_page: 10 // Show only one item per page
    });
}

function getRobotRunningStatus() {
    $.ajax({
        type: "post",
        data: {},
        url: "WebForm1.aspx/getRobotRunningStatus",
        contentType: "application/json",
        beforeSend: function () {
            $('#divRobotRunningStatusContainer').block({ message: null });
        },
        complete: function () {
            $('#divRobotRunningStatusContainer').unblock();
        },
        success: function (r) {
            $("#divRobotRunningStatus").html(r.d);
        },
        error: function (x, y, z) {
            alert("error");
        }
    });
}
function getList(pageNo) {
    var d = '{ pageNumber: ' + pageNo + ' }';
    $.ajax({
        type: "post",
        data: d,
        url: "WebForm1.aspx/ListEnrollments",
        contentType: "application/json",
        beforeSend: function () {
            $('#divList').block({ message: null });
        },
        complete: function () {
            $('#divList').unblock();  
        },
        success: function (r) {
            if (r.d.OperationStatus == true) {
                $("#divResult").html(r.d.Result);
                buildItemsPager(r.d.CurrentPage, r.d.TotalRecords);
            }
        },
        error: function (x, y, z) {
            alert("error");
        }
    });

    

}
function addECCodeCSVList() {
    var d = '{e:"' + $("#txtECCodeCSVList").val() + '"}';

    $.ajax({
        type: "post",
        data: d,
        url: "WebForm1.aspx/AddECCodeList",
        contentType: "application/json",
        error: function (x, y, z) {
            alert("error");
        }
    });
}
function addEnrollCSVList() {
    var d = '{e:"' + $("#txtEnrCSVList").val() + '"}';

    $.ajax({
        type: "post",
        data: d,
        url: "WebForm1.aspx/AddEnrollmentCSVList",
        contentType: "application/json",
        error: function (x, y, z) {
            alert("error");
        }
    });
}
function addEnroll() {
    var d = '{ pageNumber: 1 }';

    var d = '{e:"' + $("#txtEnr").val() + '"}';

    $.ajax({
        type: "post",
        data: d,
        url: "WebForm1.aspx/AddEnrollment",
        contentType: "application/json",
        success: function (r) {
            //                    try {
            //                        if (r.d == true)
            //                            alert("siccess");
            //                    }
            //                    catch (ex) {
            //                        alert("failed");
            //                    }

        },
        error: function (x, y, z) {
            alert("error");
        }
    });
}
function getStatus() {

    var d = '{e:"' + $("#txtEnr").val() + '"}';

    $.ajax({
        type: "post",
        data: d,
        url: "WebForm1.aspx/getStudent",
        contentType: "application/json",
        success: function (r) {
            try {
                if (r.d.Status == 6)
                    alert(r.d.FullName);
            }
            catch (ex) {

            }

        },
        error: function (x, y, z) {
            alert("error");
        }
    });

    //            $.ajax({
    //                type: "POST",
    //                contentType: "application/json",
    //                data: "{}",
    //                url: "WebForm2.aspx/S",
    //                dataType: "json",
    //                success: function (data) {
    //                    $(data.d).each(function (index, item) {
    //                        $("#country").append($("<option>").val(item.CountryID).html(item.CountryName));
    //                    });
    //                },
    //                error: function (XMLHttpRequest, textStatus, errorThrown) {
    //                    debugger;
    //                }
    //            });

    //var d = {p:1};



    //            $.ajax({
    //                url: "WebForm2.aspx/S",
    //                type: "POST",
    //                contentType: "application/json; charset=utf-8",
    //                data: "{}",
    //                dataType: "json",
    //                complete: function (data, c, e) {
    //                    alert('Load was performed.');
    //                },
    //                success: function (r) {
    //                    var ococ = r;
    //                    alert(r);
    //                },
    //                error: function (XMLHttpRequest, textStatus, errorThrown) {
    //                    alert("rre");
    //                 }

    //            });
    //            $.post("WebForm1.aspx/getStudent", { e: $("#txtEnr").val() }, function (o) { alert(o.d.status()); }, "json");
}